﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CLVisionEICS;
using Newtonsoft.Json.Linq;
using static System.Net.Mime.MediaTypeNames;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        CLEICSClient cLEICSClient = new CLEICSClient();
        private void button1_Click(object sender, EventArgs e)
        {
            //CLEICSClientCaller.IntMqttClient("192.168.1.45", 27011, "admin", "admin", "eics/report", "123456/notify", out int code, out string text, out _);

            //CLEICSClientCaller.SubscribeTopic(out  code, out  text, out _, "123456/notify");


            cLEICSClient.EventReceivedMessage += (msg) =>
            {
                this.BeginInvoke(new Action(() => { richTextBox1.AppendText("收到数据：" + msg + "\r\n"); }));
            };

            string path = @"D:\_A1_DevelopRepository\21_CLVisionEICS\1_File\TestTelegramSetting - 数据类型为字符.cdat";
            cLEICSClient.IntMqttClient("192.168.1.45", 27011, "admin", "admin", "eics/report", "123456/notify", out int code, out string text, path);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            cLEICSClient.SubscribeTopic(out int code, out string text, "123456/notify");


        }

        private void button3_Click(object sender, EventArgs e)
        {
            cLEICSClient.PublishData("eics/report", cLEICSClient.eicsJson.ToString(), MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce, out int code, out string text);
            bool b = cLEICSClient.ReceiveDataWithTimeout(out string receivedMessage, out code, out text, 1, 1);
            if (!b)
            {
                MessageBox.Show($"超时！");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            string ssss = "{\r\n    \"PcsDetails\": [\r\n        {\r\n            \"TestName\": \"AI露铜\",\r\n            \"TestResult\": \"NOK\",\r\n            \"TestValue\": \"13200\",\r\n            \"LowLimit\": \"100\",\r\n            \"UpLimit\": \"20000\",\r\n            \"Unit\": \"Pixel\",\r\n            \"PartSeq\": null,\r\n            \"PinSeq\": null,\r\n            \"TestType\": null,\r\n            \"OperatorName\": null,\r\n            \"VerifyResult\": null,\r\n            \"VerifyOperatorName\": null,\r\n            \"VerifyTime\": null,\r\n            \"DefectCode\": null,\r\n            \"BubbleValue\": null,\r\n            \"TestFile\": null,\r\n            \"ImagePath\": null,\r\n            \"Description\": null,\r\n            \"StrValue1\": \"1.0\",\r\n            \"StrValue2\": \"2.5\",\r\n            \"StrValue3\": \"3.0\",\r\n            \"StrValue4\": null\r\n        },\r\n        {\r\n            \"TestName\": \"AI露铜\",\r\n            \"TestResult\": \"NOK\",\r\n            \"TestValue\": \"88888\",\r\n            \"LowLimit\": \"100\",\r\n            \"UpLimit\": \"20000\",\r\n            \"Unit\": \"Pixel\",\r\n            \"PartSeq\": null,\r\n            \"PinSeq\": null,\r\n            \"TestType\": null,\r\n            \"OperatorName\": null,\r\n            \"VerifyResult\": null,\r\n            \"VerifyOperatorName\": null,\r\n            \"VerifyTime\": null,\r\n            \"DefectCode\": null,\r\n            \"BubbleValue\": null,\r\n            \"TestFile\": null,\r\n            \"ImagePath\": null,\r\n            \"Description\": null,\r\n            \"StrValue1\": \"6.0\",\r\n            \"StrValue2\": \"7.5\",\r\n            \"StrValue3\": \"8.0\",\r\n            \"StrValue4\": null\r\n        }\r\n    ]\r\n}";


            //var ff = JObject.Parse(ssss)["PcsDetails"];

            //cLEICSClient.eicsJson["PcsDetails"] = ff;


            cLEICSClient.SetEICSValueByArrayString(ssss, out _, out string txt);


        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
